/* Copyright(C): Leaf Johnson 2009,2010

    This file is part of leaf-lib.

    leaf-lib is free software: you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    leaf-lib is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public License
    along with leaf-lib.  If not, see <http://www.gnu.org/licenses/>.


 * 
 * 
 */


#ifndef CMTMSG_H_INCLUDED
#define CMTMSG_H_INCLUDED
#include <leaf/types.h>
#include <leaf/vector.h>
#include <devices_ext/cmtmid.h>

#define CMT_MSG_PREAMBLE   ((uint8_t)0xFF)
typedef uint8_t CmtMsgId;
typedef struct{
	CmtMsgId mid;
	uint16_t size;
	Vector   data;
} *pCmtMsg, CmtMsg;
typedef int16_t Angle;
typedef struct{
        Angle x;   /* X轴旋转量(侧斜) */
        Angle y;  /* Y轴旋转量(倾斜) */
        Angle z;    /* Z轴旋转量(方向) */
}*pCmtIntGroup, CmtIntGroup;

void cmtmsg_init(CmtMsg *msg, uint16_t datasize);
void cmtmsg_setid(CmtMsg *msg, CmtMsgId id);
void cmtmsg_append(CmtMsg *msg, const void *data, uint16_t len);
void cmtmsg_append_byte(CmtMsg *msg, uint8_t data);
void cmtmsg_reset(CmtMsg *msg);
void cmtmsg_free(CmtMsg *msg);
uint8_t cmtmsg_byte(const CmtMsg *msg, uint16_t idx);
float cmtmsg_get_float(const CmtMsg *msg, uint16_t idx);
int16_t cmtmsg_get_int16(const CmtMsg *msg, uint16_t idx);
int16_t cmtmsg_get_angle(const CmtMsg *msg, uint16_t idx);
double cmtmsg_get_f1220(const CmtMsg *msg, uint16_t idx);
int be2le_16( const void *resbuf );
int cmt_msg_get_intgroup( pCmtMsg msg, size_t idx, pCmtIntGroup orient);
Angle cmt_adjust_angle(Angle a);

#ifdef _STDIO_H_
void cmtMsgDisplay(CmtMsg *msg, FILE *dev);
#endif

#endif  /* CMTMSG_H_INCLUDED */
